<?php
header("content-type:text/html;charset=utf-8");
include "../../public/config/config.php";
include "../../public/include/page_tel.class.php";
include "../../public/include/funcs.php";
$link=conn($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);
$self=substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/')+1);
$obj=new page($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);

$tid=$_REQUEST['tid'];
$is_here=$_REQUEST['is_here'];
$type=$_REQUEST['type'];
$keyword=$_REQUEST['keyword'];
$arr=$obj->listData("tels",10,$tid,$is_here,$type,$keyword);
$sel_arr[$type]="selected";
$href0=$self."?tid=".$tid."&is_here=0";
$href1=$self."?tid=".$tid."&is_here=1";
if($tid){
	$typeName=select($link, "tel_type","id=$tid");
}else{
	$typeName['0']['tname']="所有数据";
}
if($tid=='1'){
	$cfg_indexname='康承贝健';
}

if($_POST['add_tel']=="add_tel"){
	if($tid){
		$add_arr['tid']=$_POST['tid'];
		$add_arr['is_here']=1;
		$add_arr['uname']=$_POST['uname'];
		$add_arr['tel']=$_POST['tel'];
		$add_arr['create_time_int']=time();
		$re=add($link, "tels", $add_arr);
		if($re){
			echo "<script>";
			echo "alert('添加成功！');";
			echo "</script>";
		}
	}else{
		echo "<script>";
		echo "alert('未指定分类！');";
		echo "</script>";
	}
}

//echo "<pre>";
//print_r($arr);
//echo "</pre>";
?>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<title><?php echo $typeName['0']['tname'];?>通讯集 -- <?php echo $cfg_indexname;?></title>
	
	<!-- Bootstrap -->
	<link href="/public/css/bootstrap.min.css" rel="stylesheet">
	<link href="/public/css/main.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" href="tel.css" />
	
	<!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
	<!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
	<![endif]-->
</head>
<body>
<?php //include "../../public/include/head.php";?>
<div class="t_img">
	<img class="w_100" src="banner.jpg"/>
</div>
<div class="container bg_liter tab">
	<h3 class="text-center bg-primary lhei"><?php echo $typeName['0']['tname'];?> - 通讯集</h3>
	<p class="btn btn-info w_100" id="search_tel">搜索功能</p>
	<div class="h10"></div>
	<div class="search_tel" id="search_tel_div" >
		<form action="<?php echo $self;?>" method="post">
			<div class="form-group">
				搜索类型：<select name="type" class="form-control w80 in_bl">
					<option <?php echo $sel_arr['uname']?> value="uname">姓名</option>
					<option <?php echo $sel_arr['tel']?> value="tel">电话</option>
				</select>
			</div>
			<div class="form-group">
				搜索关键字：<input type="text" name="keyword" class="form-control w200 in_bl" value="<?php echo $keyword;?>" />
				<input type="submit" class="btn btn-info" value="搜索"/>
			</div>
		</form>
	</div>
	<span><a href="<?php echo $href0;?>" class="btn btn-danger" >查看离职员工</a></span>
	<span><a href="<?php echo $href1;?>" class="btn btn-primary" >查看在职员工</a></span>
	<span class="btn btn-success" id="add_tel" >添加联系人</span>
	<br /><br />
	<div class="add_tel" id="add_tel_div">
		<form class="form-inline" action="<?php echo $self;?>" method="post">
			<input type="hidden" name="add_tel" value="add_tel" />
			<input type="hidden" name="tid" value="<?php echo $tid;?>" />
			<input type="hidden" name="page" value="<?php echo $page;?>" />
			<input type="hidden" name="is_here" value="<?php echo $is_here;?>" />
			<input type="hidden" name="type" value="<?php echo $type;?>" />
			<input type="hidden" name="keyword" value="<?php echo $keyword;?>" />
			姓名：<input type="text" class="form-control" name="uname" value="" />
			电话：<input type="text" class="form-control" name="tel" value="" />
			<input type="submit" class="btn btn-success" value="提交添加"/>
		</form>
	</div>
	<table class="table table-hover bg-info"  border="2" cellspacing="0" cellpadding="0">
		<tr>
			<th>编号</th>
			<th>姓名</th>
			<th>电话</th>
			<th>操作</th>
		</tr>
<?php
$i=0;
foreach($arr as $v){
$i++;
?>			
		<tr>
			<td><?php echo $i;?></td>
			<td><?php echo $v['uname'];?></td>
			<td><?php echo $v['tel'];?></td>
			<td><a href="tel:<?php echo $v['tel'];?>" class="btn btn-success">拨打</a></td>
		</tr>
<?php
}
?>	
		<tr>
			<td colspan="4">
				<?php echo $obj->showPage();?>
			</td>
		</tr>		
	</table>
</div>
<div class="hei_50"></div>
<?php //include "../../public/include/footer.php";?>
<script type="text/javascript">
document.getElementById("add_tel").onclick=function(){
	document.getElementById("add_tel_div").style.display="block";
}
document.getElementById("search_tel").onclick=function(){
	document.getElementById("search_tel_div").style.display="block";
}
</script>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script type="text/javascript" src="/public/js/jquery-3.3.1.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script type="text/javascript" src="/public/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/public/js/footer.js"></script>
</body>
</html>